#ifndef _WAV_FILE_HEAD_H
#define _WAV_FILE_HEAD_H

#include <iostream>
#include <vector>

using namespace std;

typedef struct wavfile_header
{
	char riff_tag[4]; //'R','I','F','F'
	int  riff_length; //整个file_size的大小减去chunkID和chunkSize的大小，
	                  //即file_size=chunkSize+8
	char wave_tag[4]; //'W','A','V','E'
	//---------------------------------------------

	char  fmt_tag[4];      //'f''m''t'' '
	int   fmt_length;      //fmt chunk 的大小，一般有 16/18/20/22/40 字节
	short audio_format;    //编码格式，如果上述取值为 16，则此值通常为 1，
	                       //代表该音频的编码方式是 PCM 编码
	short num_channels;    //声道数目，1 代表单声道，2 代表双声道
	int   sample_rate;     //采样频率，8/16/44.1/48/64/96/192 kHZ
	int   byte_rate;       //传输速率，每秒的字节数，
	                       //计算公式为:SampleRate * FmtChannels * BitsPerSample/8
	short block_align;     //The number of bytes for one sample including all channels.
	                       //公式为： BitsPerSample*FmtChannels/8
	short bits_per_sample; //采样位数，一般有8/16/24/32/64 bit

	//---------------------------------------------
	char data_tag[4]; //"data"
	int  data_length; //原始音频数据的大小
} wavfile_header_t;   //head size:44byte

class WavFile
{
public:
	WavFile(const string &filename);
	void setParams(int sampleRate, int channels, int sampleBits);
	bool writeData(uint8_t *data, uint32_t size);

private:
	string           filename;
	wavfile_header_t header;
};

#endif
